package com.simba.server.commands.impl.del;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;
import com.simba.server.components.data.DeleteData;

/**
 * @author create by kavin
 * @date 2020/11/1 2:41
 */
public class DelPacketOffReportCmd implements ICommand {
    public static final String NAME = "DelPacketOffReportCmd";
    private final DeleteData delInfo;
    private final String sql = "delete from tt_packet_off_info_report where recordTime<? limit 10000;";

    public DelPacketOffReportCmd(DeleteData delInfo)
    {
        this.delInfo = delInfo;
    }

    @Override
    public String getName()
    {
        return DelPacketOffReportCmd.NAME;
    }

    @Override
    public Boolean run(Object params)
    {
        Boolean ret = false;

        if (!(params instanceof DbOperator))
        {
            return ret;
        }

        try
        {
            DbOperator dbOperator = (DbOperator) params;

            dbOperator.prepareStatement(this.sql);
            dbOperator.setTimestamp(1, this.delInfo.getDeleteBeforeTime());

            int delCount = dbOperator.executeUpdate();
            if (delCount > 0)
            {
                this.delInfo.setDelCount(delCount);
            }
            ret = true;
        }
        catch (Exception ex)
        {
            ret = false;
        }

        return ret;
    }
}
